function w = Ku(Kcal,u,params)

[m,n,c] = size(u);

Q = params.order;

switch Q
    case 1
        K = Kcal{1};
        w = cat(2,K{1}*u(:),...
                  K{2}*u(:));
        
    case 2
        K = Kcal{2};
        w = cat(2,K{1}{1}*u(:),...
                  K{2}{1}*u(:),...
                  K{1}{2}*u(:),...
                  K{2}{2}*u(:));
        
    case 3
        K = Kcal{3};
        w = cat(2,K{1}{1}{1}*u(:),...
                  K{1}{2}{1}*u(:),...
                  K{1}{1}{2}*u(:),...
                  K{1}{2}{2}*u(:),...
                  K{2}{1}{1}*u(:),.....
                  K{2}{2}{1}*u(:),...
                  K{2}{1}{2}*u(:),...
                  K{2}{2}{2}*u(:));
end

w = reshape(w,m-3,n-3,2^Q);
